#include "common/config/config.h"
#include "common/log/log.h"

#include "field_kind.h"

namespace F2FB
{

namespace Database
{

std::vector<unsigned> FieldKind::ids(
    sqlite::database& database
)
{
    std::vector<unsigned> result;
    database << "SELECT id FROM field_kinds;"
        >> [&result](unsigned id)
    {
        result.emplace_back(id);
    };
    return result;
}

std::vector<std::shared_ptr<Entity>> FieldKind::entities(
    sqlite::database& database
)
{
    const auto sqlStr = "SELECT "
                        "  id "
                        ", value_type "
                        ", caption "
                        ", description "
                        ", issue_kind_id "
                        ", is_system "
                        "FROM field_kinds;";

    auto query = database << sqlStr;
    std::vector<std::shared_ptr<Entity>> result;
    query >>
        [&result](
            unsigned id,
            unsigned valueType,
            std::string caption,
            std::string description,
            unsigned issueKindId,
            bool isSystem
        )
    {
        auto entity = std::make_shared<FieldKind>();
        entity->m_data["id"] = id;
        entity->m_data["value_type"] = valueType;
        entity->m_data["caption"] = caption;
        entity->m_data["description"] = description;
        entity->m_data["issue_kind_id"] = issueKindId;
        entity->m_data["is_system"] = isSystem;
        result.push_back(entity);
    };
    return result;
}

} // namespace Database

} // namespace F2FB
